//
// Created by XiongYingqi on 14-5-22.
// Copyright (c) 2014 XiongYingqi. All rights reserved.
//

#import "XYQImageHelper.h"


//@implementation UIImage (Tint)
//- (UIImage *)
//imageWithTintColor:(UIColor *)tintColor { //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
//    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
//    [tintColor setFill];
//    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
//    UIRectFill(bounds); //Draw the tinted image in context
//    [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
//    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return tintedImage;
//}
//@end

// UIImage+Tint.m #import "UIImage+Tint.h"

@implementation XYQColor

UIColor *defaultColor;

+ (UIColor *)defaultColor {
    if (defaultColor == nil) {
        defaultColor = [UIColor colorWithRed:0 green:0.478431 blue:1 alpha:1];
    }
    return defaultColor;
}
@end


@implementation UIImage (Tint)


- (UIImage *)imageWithTintColor:(UIColor *)tintColor {
    return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];
}

- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor {
    return [self imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];
}

- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode { //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
    [tintColor setFill];
    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
    UIRectFill(bounds); //Draw the tinted image in context
    [self drawInRect:bounds blendMode:blendMode alpha:1.0f];
    if (blendMode != kCGBlendModeDestinationIn) {[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];}
    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return tintedImage;
}
@end
